import javax.swing.SwingUtilities;
import java.text.NumberFormat;
import java.util.Locale;
//Test

public class Navi {

	/**
	 * @param args
	 */

	public static void main(String[] args) throws InterruptedException{
		ReadSerialNmea nmea1 =new ReadSerialNmea(args[0]);
		WriteSerialNmea nmeaOut = new WriteSerialNmea(args[1],nmea1.serialPort);
						
		Parser parser1 =  new Parser();
		Display4 inst = new Display4();

		int nmea1_counter =0;
		long zstVorher = 0;
		long zstNachher = 0;

		inst.setLocationRelativeTo(null);
		inst.setVisible(true);

		while (1==1){
			if (nmea1.nmea_counter > nmea1_counter){
				if (nmea1.nmea_counter - nmea1_counter > 1) {
					System.out.println("WARNING:   Lost "+(nmea1.nmea_counter - nmea1_counter-1)+" NMEA Sentences");
					nmea1_counter = nmea1.nmea_counter -1;
				}
				nmea1_counter ++;
				parser1.parse(nmea1.nmea_string);
				nmeaOut.write(nmea1.nmea_string); //repeater
				
				NumberFormat n = NumberFormat.getInstance(Locale.UK);
				n.setMaximumFractionDigits(1);
				n.setMinimumIntegerDigits(1);
				n.setMinimumIntegerDigits(3);

				String nmeaMWV = "$WIMWV,"+n.format(Parser.twd)+",T,"+n.format(Parser.tws)+",N,A";
				nmeaMWV= nmeaMWV + "*" +parser1.GetCheckSum(nmeaMWV);
				nmeaOut.write(nmeaMWV); //calculated data

				if (System.currentTimeMillis() >= zstVorher + 1000){
					zstVorher = System.currentTimeMillis();
					inst.setWerte(parser1.sog, parser1.aws,parser1.tws,Parser.awd, Parser.twd);
					zstNachher = System.currentTimeMillis();
					System.out.println("DEBUG:     GUI display time: " + ((zstNachher - zstVorher)) + " msec");
				}
			}
			Thread.sleep(1);
		}
	}

}
